/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;

import com.bayu.services.entity.K3;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/**
 *
 * @author Bayu
 */
@Repository("k3Dao")
@Transactional
public class K3Dao {
    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
	hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Transactional(readOnly = false)
    public void save(K3 k3) {
       hibernateTemplate.saveOrUpdate(k3);
    }
    @Transactional(readOnly = false)
    public void delete(K3 k3) {
        hibernateTemplate.delete(k3);
    }
    @Transactional(readOnly = false)
    public void update(K3 k3) {
         hibernateTemplate.update(k3);
    }

    public List<K3> getAll(String query) {
        return hibernateTemplate.find(query);
        
    }

    public List<K3> getAllByDate(String start, String end) {
        return hibernateTemplate.find("from K3 where date between '"+start+"' and '"+end+"' order by date asc");
    }

    public List<K3> getById(Long id) {
        return hibernateTemplate.find("from K3 where id="+id);
    }

    public List<K3> getAllByMonth(String month) {
       return hibernateTemplate.find("from K3 where MONTH(date)='"+month+"' order by date asc");
    }
     public List custom(String query){
       return hibernateTemplate.find(query);

    }
}
